#!/usr/bin/python

# Copyright 2012 Sergio, Raul, Dorival. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

import subprocess

def Cmd(command, verbose=False, debug=False):
    if debug:
        print '=================================================='
        print cmd
        print '=================================================='
    spr = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out = spr.stdout.read()
    err = spr.stderr.read().strip()
    if verbose:
        print out
        print err
    return out, err

idxfn = 'index.html'
licen = open('../LICENSE.txt', 'r').read()

def header(title):
    return """<html>
<head>
<meta http-equiv=\\"Content-Type\\" content=\\"text/html; charset=utf-8\\">
<title>%s</title>
<link type=\\"text/css\\" rel=\\"stylesheet\\" href=\\"static/style.css\\">
<link type=\\"text/css\\" rel=\\"stylesheet\\" href=\\"static/prettify.css\\">
<script type=\\"text/javascript\\" src=\\"static/prettify.js\\"></script>
<script type=\\"text/javascript\\" src=\\"static/godocs.js\\"></script>
<script type=\\"text/javascript\\" src=\\"static/fixlnk.js\\"></script>
</head>
<body onload=\\"prettyPrint()\\">
<div id=\\"page\\">""" % title

def footer():
    return """</div><!-- page -->
<div id=\\"footer\\">
<br /><br />
<hr>
<pre class=\\"copyright\\">
%s</pre><!-- copyright -->
</div><!-- footer -->
</body>
</html>""" % licen

Cmd('echo "'+header('Gemlab &ndash; Documentation')+'" > '+idxfn)
mesh = open('mesh.htm', 'r').read()
Cmd('echo "'+mesh+'" >> '+idxfn)
Cmd('echo "'+footer()+'" >> '+idxfn)
